package rd.hardcore.ui.nav 
{
	import aze.motion.eaze;
	import flash.display.BlendMode;
	import flash.display.GradientType;
	import flash.display.MovieClip;
	import flash.display.Shader;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.DropShadowFilter;
	import flash.geom.Matrix;
	
	/**
	 * ...
	 * @author Romain Prache
	 */
	public class NavItem extends MovieClip
	{
		
		
		protected var selectedShape:Sprite;
		protected var _id:int;
		
		protected var body	: Shape;
		protected var ctrl 	: Shape;
		
		public function NavItem() 
		{
			buttonMode = true;
			mouseChildren = false;
			
			body = new Shape();
			body.graphics.beginFill(0x666666);
			body.graphics.drawCircle(0, 0, 2);
			body.graphics.endFill();
			addChild(body);
			
			selectedShape = new Sprite();
			selectedShape.graphics.beginFill(0xFFFFFF);
			selectedShape.graphics.drawCircle(0, 0, 2);
			selectedShape.graphics.endFill();
			selectedShape.alpha = 0;
			addChild(selectedShape);
			
			ctrl = new Shape();
			ctrl.graphics.beginFill(0,0);
			ctrl.graphics.drawCircle( 0, 0, 8);
			ctrl.graphics.endFill();
			addChildAt(ctrl, 0);
			
			body.filters = [new DropShadowFilter(0, 90, 0x000000, .4, 3, 3,1,3)];
			//cacheAsBitmap = true;
			blendMode = BlendMode.LAYER;

			
			addEventListener(MouseEvent.ROLL_OVER, 	handleOver);
			addEventListener(MouseEvent.ROLL_OUT, 	handleOut);
		}
		
		public function select() : void
		{
			mouseEnabled = false;	
			
			removeEventListener(MouseEvent.ROLL_OVER, 	handleOver);
			removeEventListener(MouseEvent.ROLL_OUT, 	handleOut);
			
			eaze(selectedShape).to(.4, { alpha : 1  } );
			eaze(this).to(.3, { alpha:1 } );
		}
		
		public function unselect() : void
		{
			mouseEnabled = true;
			
			eaze(selectedShape).to(.3, { alpha : 0  } );
			
			addEventListener(MouseEvent.ROLL_OVER, 	handleOver);
			addEventListener(MouseEvent.ROLL_OUT, 	handleOut);
		}
		
		private function handleOver(e:MouseEvent=null):void 
		{
			eaze(this).to(.3, { alpha:.7 } );
		}
		
		private function handleOut(e:MouseEvent=null):void 
		{
			eaze(this).to(.3, { alpha:1 } );
		}

		public function dispose() : void
		{
			removeEventListener(MouseEvent.ROLL_OVER, 	handleOver);
			removeEventListener(MouseEvent.ROLL_OUT, 	handleOut);
			
			body = null;
			ctrl = null;
			selectedShape = null;
		}
		
		/* ID */
		public function get id():int { return _id; }
		
		public function set id(value:int):void { _id = value; }
		
		
	}

}